package com.hontech.bvapp2.ui.parts.heat

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.FrameLayout
import com.hontech.bvapp2.R
import com.hontech.bvapp2.device.cp.Heat
import com.hontech.bvapp2.ui.dialog.runProg
import com.hontech.bvapp2.ui.dialog.runProg2
import com.hontech.bvapp2.ui.view.LabelInput
import com.hontech.bvapp2.ui.view.LabelSpinner
import com.hontech.bvapp2.utils.onClick

class HeatArgParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_heat_arg, this)
        val sp = view.findViewById<LabelSpinner>(R.id.id_heat_arg_sp_types)
        val btnSet = view.findViewById<Button>(R.id.id_heat_arg_btn_set)
        val btnGet = view.findViewById<Button>(R.id.id_heat_arg_btn_get)
        val li = view.findViewById<LabelInput>(R.id.id_heat_arg_li)

        btnSet.onClick {
            val name = sp.selectText()
            val ctrl = sp.selectIndex()
            runProg("设置", name) {
                Heat.setArg(ctrl, li.textInt())
            }
        }

        btnGet.onClick {
            val name = sp.selectText()
            val ctrl = sp.selectIndex()
            runProg2("获取:$name", "") {
                val value = Heat.getArg(ctrl)
                "$name=$value"
            }
        }
    }
}